#!/usr/bin/python -S
"""
See how much slower it is to read char by char vs line-by line.
"""

__author__ = 'Andy Chu'


import os
import sys
import time


class Error(Exception):
  pass


def main(argv):
  """Returns an exit code."""

  style = argv[1]
  if style == 'char':
    while True:
      c = os.read(sys.stdin.fileno(), 1)
      if c == '':
        break
      sys.stdout.write(c)
  elif style == 'line':
    while True:
      line = sys.stdin.readline()
      if line  == '':
        break
      sys.stdout.write(line)
  else:
    raise RuntimeError(style)

  return 0


if __name__ == '__main__':
  try:
    sys.exit(main(sys.argv))
  except Error, e:
    print >> sys.stderr, e.args[0]
    sys.exit(1)
